#include <algorithm>
#include <iostream>
#include <iosfwd>
#include "txtwc.h"

TxtWordCounter::TxtWordCounter(std::string const & file) : WordCounter(file)
{
}

unsigned TxtWordCounter::count()
{
    if(wasModified())
    {
        std::ifstream f(file_.c_str());
        counter_ = std::count_if(std::istreambuf_iterator<char>(f),
             std::istreambuf_iterator<char>(), NewWord());
        f.close();
    }
    return counter_;
}
 